<%@ page import="jakarta.servlet.http.Cookie" %><%--
  Created by IntelliJ IDEA.
  User: LH
  Date: 2022/9/9
  Time: 16:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
</head>
<body>
<% Cookie[] cookies = request.getCookies();
    String name=null;
    String password=null;
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals("name")) {
             name = cookie.getValue();
        }else if (cookie.getName().equals("password")){
            password=cookie.getValue();
        }
    }
    //若已保存了登录
    if (name!=null&&password!=null){
        response.sendRedirect("index.jsp");
    }
%>
<form action="doLogin.jsp" method="post">
    用户名： <input type="text" id="username" name="username"><br>
    密码：   <input type="password" id="password" name="password"><br>
    <input type="checkbox" id="LoginFree" name="freeLogin">七天免登录
    <button  type="submit" id="submit">提交</button>
    <button >重置</button>
</form>
</body>

<script>
    // var ischeck;
    // var loginFree = document.getElementById("LoginFree");
    // if (loginFree.checked) {
    //     ischeck=true;
    // }
    // var username = document.getElementById("username").value;
    // var password = document.getElementById("password").value;
    // var xmlHttpRequest = new XMLHttpRequest();
    // document.getElementById("submit").onclick=function (){
    //     xmlHttpRequest.open("POST","/lab03/login",true);
    //     xmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    //     xmlHttpRequest.send("username="+username+"&password="+password)
    // }


</script>